package model;

import java.sql.*;
import java.util.Date;
import dal.*;
import util.*;

public class FileModel implements IModel {

	public static class FieldNames {
		public static String Id = "Id";
		public static String IdDocument = "IdDocument";
		public static String ObjectType = "ObjectType";
		public static String ObjectId = "ObjectId";
		public static String VersionTxt = "VersionTxt";
		public static String VersionNo = "VersionNo";
		public static String IdPrevVersion = "IdPrevVersion";
		public static String Name = "Name";
		public static String Code = "Code";
		public static String Description = "Description";
		public static String Remark = "Remark";
		public static String FileName = "FileName";
		public static String Ext = "Ext";
		public static String MimeType = "MimeType";
		public static String SaveMode = "SaveMode";
		public static String FilePath = "FilePath";
		public static String Status = "Status";
		public static String Created = "Created";
		public static String Creator = "Creator";
		public static String Updated = "Updated";
		public static String Updator = "Updator";
		public static String Deleted = "Deleted";
		public static String DeletionTime = "DeletionTime";

	}

	public class ErrorMessages {
		public String Id = "";
		public String IdDocument = "";
		public String ObjectType = "";
		public String ObjectId = "";
		public String VersionTxt = "";
		public String VersionNo = "";
		public String IdPrevVersion = "";
		public String Name = "";
		public String Code = "";
		public String Description = "";
		public String Remark = "";
		public String FileName = "";
		public String Ext = "";
		public String MimeType = "";
		public String SaveMode = "";
		public String FilePath = "";
		public String Status = "";
		public String Created = "";
		public String Creator = "";
		public String Updated = "";
		public String Updator = "";
		public String Deleted = "";
		public String DeletionTime = "";

	}

	public ErrorMessages errMsgs = new ErrorMessages();

	public String[] errMsgList = null;

	// private variables
	private int _id = Integer.MIN_VALUE;
	private int _id_document = Integer.MIN_VALUE;
	private String _object_type = null;
	private int _object_id = Integer.MIN_VALUE;
	private String _version_txt = null;
	private int _version_no = Integer.MIN_VALUE;
	private int _id_prev_version = Integer.MIN_VALUE;
	private String _name = null;
	private String _code = null;
	private String _description = null;
	private String _remark = null;
	private String _file_name = null;
	private String _ext = null;
	private String _mime_type = null;
	private int _save_mode = Integer.MIN_VALUE;
	private String _file_path = null;
	private int _status = Integer.MIN_VALUE;
	private Date _created = null;
	private int _creator = Integer.MIN_VALUE;
	private Date _updated = null;
	private int _updator = Integer.MIN_VALUE;
	private boolean _deleted = false;
	private boolean _isdeletedSet = false;
	private Date _deletion_time = null;

	public FileModel() {
	}

	// get/set
	public int getId() {
		return _id;
	}

	public void setId(int value) {
		_id = value;
	}

	public String getIdToString() {
		if (_id == Integer.MIN_VALUE || _id == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_id);
		}
	}

	public int getIdDocument() {
		return _id_document;
	}

	public void setIdDocument(int value) {
		_id_document = value;
	}

	public String getIdDocumentToString() {
		if (_id_document == Integer.MIN_VALUE
				|| _id_document == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_id_document);
		}
	}

	public String getObjectType() {
		return _object_type;
	}

	public void setObjectType(String value) {
		_object_type = value;
	}

	public String getObjectTypeToString() {
		if (_object_type != null) {
			return HtmlUtil.genHtml(_object_type);
		} else {
			return "";
		}
	}

	public int getObjectId() {
		return _object_id;
	}

	public void setObjectId(int value) {
		_object_id = value;
	}

	public String getObjectIdToString() {
		if (_object_id == Integer.MIN_VALUE || _object_id == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_object_id);
		}
	}

	public String getVersionTxt() {
		return _version_txt;
	}

	public void setVersionTxt(String value) {
		_version_txt = value;
	}

	public String getVersionTxtToString() {
		if (_version_txt != null) {
			return HtmlUtil.genHtml(_version_txt);
		} else {
			return "";
		}
	}

	public int getVersionNo() {
		return _version_no;
	}

	public void setVersionNo(int value) {
		_version_no = value;
	}

	public String getVersionNoToString() {
		if (_version_no == Integer.MIN_VALUE
				|| _version_no == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_version_no);
		}
	}

	public int getIdPrevVersion() {
		return _id_prev_version;
	}

	public void setIdPrevVersion(int value) {
		_id_prev_version = value;
	}

	public String getIdPrevVersionToString() {
		if (_id_prev_version == Integer.MIN_VALUE
				|| _id_prev_version == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_id_prev_version);
		}
	}

	public String getName() {
		return _name;
	}

	public void setName(String value) {
		_name = value;
	}

	public String getNameToString() {
		if (_name != null) {
			return HtmlUtil.genHtml(_name);
		} else {
			return "";
		}
	}

	public String getCode() {
		return _code;
	}

	public void setCode(String value) {
		_code = value;
	}

	public String getCodeToString() {
		if (_code != null) {
			return HtmlUtil.genHtml(_code);
		} else {
			return "";
		}
	}

	public String getDescription() {
		return _description;
	}

	public void setDescription(String value) {
		_description = value;
	}

	public String getDescriptionToString() {
		if (_description != null) {
			return HtmlUtil.genHtml(_description);
		} else {
			return "";
		}
	}

	public String getRemark() {
		return _remark;
	}

	public void setRemark(String value) {
		_remark = value;
	}

	public String getRemarkToString() {
		if (_remark != null) {
			return HtmlUtil.genHtml(_remark);
		} else {
			return "";
		}
	}

	public String getFileName() {
		return _file_name;
	}

	public void setFileName(String value) {
		_file_name = value;
	}

	public String getFileNameToString() {
		if (_file_name != null) {
			return HtmlUtil.genHtml(_file_name);
		} else {
			return "";
		}
	}

	public String getExt() {
		return _ext;
	}

	public void setExt(String value) {
		_ext = value;
	}

	public String getExtToString() {
		if (_ext != null) {
			return HtmlUtil.genHtml(_ext);
		} else {
			return "";
		}
	}

	public String getMimeType() {
		return _mime_type;
	}

	public void setMimeType(String value) {
		_mime_type = value;
	}

	public String getMimeTypeToString() {
		if (_mime_type != null) {
			return HtmlUtil.genHtml(_mime_type);
		} else {
			return "";
		}
	}

	public int getSaveMode() {
		return _save_mode;
	}

	public void setSaveMode(int value) {
		_save_mode = value;
	}

	public String getSaveModeToString() {
		if (_save_mode == Integer.MIN_VALUE || _save_mode == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_save_mode);
		}
	}

	public String getFilePath() {
		return _file_path;
	}

	public void setFilePath(String value) {
		_file_path = value;
	}

	public String getFilePathToString() {
		if (_file_path != null) {
			return HtmlUtil.genHtml(_file_path);
		} else {
			return "";
		}
	}

	public int getStatus() {
		return _status;
	}

	public void setStatus(int value) {
		_status = value;
	}

	public String getStatusToString() {
		if (_status == Integer.MIN_VALUE || _status == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_status);
		}
	}

	public Date getCreated() {
		return _created;
	}

	public void setCreated(Date value) {
		_created = value;
	}

	public String getCreatedToString() {
		if (_created != null) {
			return StringUtil.toDateTimeString(_created);
		} else {
			return "";
		}
	}

	public int getCreator() {
		return _creator;
	}

	public void setCreator(int value) {
		_creator = value;
	}

	public String getCreatorToString() {
		if (_creator == Integer.MIN_VALUE || _creator == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_creator);
		}
	}

	public Date getUpdated() {
		return _updated;
	}

	public void setUpdated(Date value) {
		_updated = value;
	}

	public String getUpdatedToString() {
		if (_updated != null) {
			return StringUtil.toDateTimeString(_updated);
		} else {
			return "";
		}
	}

	public int getUpdator() {
		return _updator;
	}

	public void setUpdator(int value) {
		_updator = value;
	}

	public String getUpdatorToString() {
		if (_updator == Integer.MIN_VALUE || _updator == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_updator);
		}
	}

	public boolean getDeleted() {
		return _deleted;
	}

	public void setDeleted(boolean value) {
		_deleted = value;
		_isdeletedSet = true;
	}

	public boolean getDeletedSet() {
		return _isdeletedSet;
	}

	public String getDeletedToString() {
		if (_isdeletedSet) {
			return HtmlUtil.genHtml(_deleted);
		} else {
			return "";
		}
	}

	public Date getDeletionTime() {
		return _deletion_time;
	}

	public void setDeletionTime(Date value) {
		_deletion_time = value;
	}

	public String getDeletionTimeToString() {
		if (_deletion_time != null) {
			return StringUtil.toDateTimeString(_deletion_time);
		} else {
			return "";
		}
	}

	@Override
	public int[] getPrimaryKey() {
		int[] ids = new int[1];
		ids[0] = getId();
		return ids;
	}

	@Override
	public IModel readFromResultSet(ResultSet rs) throws SQLException {
		FileModel model = null;

		model = new FileModel();

		// read fields
		{
			int value = rs.getInt("id");
			if (!rs.wasNull()) {
				model.setId(value);
			}
		}
		{
			int value = rs.getInt("id_document");
			if (!rs.wasNull()) {
				model.setIdDocument(value);
			}
		}
		{
			String value = rs.getString("object_type");
			if (!rs.wasNull()) {
				model.setObjectType(value);
			}
		}
		{
			int value = rs.getInt("object_id");
			if (!rs.wasNull()) {
				model.setObjectId(value);
			}
		}
		{
			String value = rs.getString("version_txt");
			if (!rs.wasNull()) {
				model.setVersionTxt(value);
			}
		}
		{
			int value = rs.getInt("version_no");
			if (!rs.wasNull()) {
				model.setVersionNo(value);
			}
		}
		{
			int value = rs.getInt("id_prev_version");
			if (!rs.wasNull()) {
				model.setIdPrevVersion(value);
			}
		}
		{
			String value = rs.getString("name");
			if (!rs.wasNull()) {
				model.setName(value);
			}
		}
		{
			String value = rs.getString("code");
			if (!rs.wasNull()) {
				model.setCode(value);
			}
		}
		{
			String value = rs.getString("description");
			if (!rs.wasNull()) {
				model.setDescription(value);
			}
		}
		{
			String value = rs.getString("remark");
			if (!rs.wasNull()) {
				model.setRemark(value);
			}
		}
		{
			String value = rs.getString("file_name");
			if (!rs.wasNull()) {
				model.setFileName(value);
			}
		}
		{
			String value = rs.getString("ext");
			if (!rs.wasNull()) {
				model.setExt(value);
			}
		}
		{
			String value = rs.getString("mime_type");
			if (!rs.wasNull()) {
				model.setMimeType(value);
			}
		}
		{
			int value = rs.getInt("save_mode");
			if (!rs.wasNull()) {
				model.setSaveMode(value);
			}
		}
		{
			String value = rs.getString("file_path");
			if (!rs.wasNull()) {
				model.setFilePath(value);
			}
		}
		{
			int value = rs.getInt("status");
			if (!rs.wasNull()) {
				model.setStatus(value);
			}
		}
		{
			Date value = rs.getTimestamp("created");
			if (!rs.wasNull()) {
				model.setCreated(value);
			}
		}
		{
			int value = rs.getInt("creator");
			if (!rs.wasNull()) {
				model.setCreator(value);
			}
		}
		{
			Date value = rs.getTimestamp("updated");
			if (!rs.wasNull()) {
				model.setUpdated(value);
			}
		}
		{
			int value = rs.getInt("updator");
			if (!rs.wasNull()) {
				model.setUpdator(value);
			}
		}
		{
			boolean value = rs.getBoolean("deleted");
			if (!rs.wasNull()) {
				model.setDeleted(value);
			}
		}
		{
			Date value = rs.getTimestamp("deletion_time");
			if (!rs.wasNull()) {
				model.setDeletionTime(value);
			}
		}

		return model;
	}

	@Override
	public PreparedStatement genSelectStatement(Connection dbConn, IModel query)
			throws SQLException {
		String sql = "SELECT * FROM sp_file_select(:id);";
		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		FileModel obj = (FileModel) query;

		// set parameters
		st.setObject("id", obj.getId());

		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genSelectListStatement(Connection dbConn,
			IModelExt query) throws SQLException {
		String sql = "SELECT * FROM sp_file_selectList(:limit, :offset, :id,:id_document,:object_type,:object_id,:version_txt,:version_no,:id_prev_version,:name,:code,:description,:remark,:file_name,:ext,:mime_type,:save_mode,:file_path,:status,:createdFrom,:createdTo,:creator,:updatedFrom,:updatedTo,:updator,:deleted,:deletion_timeFrom,:deletion_timeTo)";

		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		FileModelExt obj = (FileModelExt) query;

		if (obj.getLimit() != Integer.MIN_VALUE) {
			st.setObject("limit", obj.getLimit());
		} else {
			st.setObject("limit", Integer.MAX_VALUE);
		}
		if (obj.getOffset() != Integer.MIN_VALUE) {
			st.setObject("offset", obj.getOffset());
		} else {
			st.setObject("offset", 0);
		}

		// set parameters
		if (obj.getId() != Integer.MIN_VALUE) {
			st.setObject("id", obj.getId());
		} else {
			st.setObject("id", null);
		}
		if (obj.getIdDocument() != Integer.MIN_VALUE) {
			st.setObject("id_document", obj.getIdDocument());
		} else {
			st.setObject("id_document", null);
		}
		if (obj.getObjectType() != null) {
			st.setObject("object_type", obj.getObjectType());
		} else {
			st.setObject("object_type", null);
		}
		if (obj.getObjectId() != Integer.MIN_VALUE) {
			st.setObject("object_id", obj.getObjectId());
		} else {
			st.setObject("object_id", null);
		}
		if (obj.getVersionTxt() != null) {
			st.setObject("version_txt", obj.getVersionTxt());
		} else {
			st.setObject("version_txt", null);
		}
		if (obj.getVersionNo() != Integer.MIN_VALUE) {
			st.setObject("version_no", obj.getVersionNo());
		} else {
			st.setObject("version_no", null);
		}
		if (obj.getIdPrevVersion() != Integer.MIN_VALUE) {
			st.setObject("id_prev_version", obj.getIdPrevVersion());
		} else {
			st.setObject("id_prev_version", null);
		}
		if (obj.getName() != null) {
			st.setObject("name", obj.getName());
		} else {
			st.setObject("name", null);
		}
		if (obj.getCode() != null) {
			st.setObject("code", obj.getCode());
		} else {
			st.setObject("code", null);
		}
		if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
			st.setObject("description", null);
		}
		if (obj.getRemark() != null) {
			st.setObject("remark", obj.getRemark());
		} else {
			st.setObject("remark", null);
		}
		if (obj.getFileName() != null) {
			st.setObject("file_name", obj.getFileName());
		} else {
			st.setObject("file_name", null);
		}
		if (obj.getExt() != null) {
			st.setObject("ext", obj.getExt());
		} else {
			st.setObject("ext", null);
		}
		if (obj.getMimeType() != null) {
			st.setObject("mime_type", obj.getMimeType());
		} else {
			st.setObject("mime_type", null);
		}
		if (obj.getSaveMode() != Integer.MIN_VALUE) {
			st.setObject("save_mode", obj.getSaveMode());
		} else {
			st.setObject("save_mode", null);
		}
		if (obj.getFilePath() != null) {
			st.setObject("file_path", obj.getFilePath());
		} else {
			st.setObject("file_path", null);
		}
		if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
			st.setObject("status", null);
		}
		if (obj.getCreatedFrom() != null) {
			st.setObject("createdFrom", obj.getCreatedFrom());
		} else {
			st.setObject("createdFrom", null);
		}
		if (obj.getCreatedTo() != null) {
			st.setObject("createdTo", obj.getCreatedTo());
		} else {
			st.setObject("createdTo", null);
		}
		if (obj.getCreator() != Integer.MIN_VALUE) {
			st.setObject("creator", obj.getCreator());
		} else {
			st.setObject("creator", null);
		}
		if (obj.getUpdatedFrom() != null) {
			st.setObject("updatedFrom", obj.getUpdatedFrom());
		} else {
			st.setObject("updatedFrom", null);
		}
		if (obj.getUpdatedTo() != null) {
			st.setObject("updatedTo", obj.getUpdatedTo());
		} else {
			st.setObject("updatedTo", null);
		}
		if (obj.getUpdator() != Integer.MIN_VALUE) {
			st.setObject("updator", obj.getUpdator());
		} else {
			st.setObject("updator", null);
		}
		if (obj.getDeletedSet()) {
			st.setObject("deleted", obj.getDeleted());
		} else {
			st.setObject("deleted", null);
		}
		if (obj.getDeletionTimeFrom() != null) {
			st.setObject("deletion_timeFrom", obj.getDeletionTimeFrom());
		} else {
			st.setObject("deletion_timeFrom", null);
		}
		if (obj.getDeletionTimeTo() != null) {
			st.setObject("deletion_timeTo", obj.getDeletionTimeTo());
		} else {
			st.setObject("deletion_timeTo", null);
		}

		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genInsertStatement(Connection dbConn, IModel model)
			throws SQLException {
		String sql = "SELECT sp_file_insert(:id_document,:object_type,:object_id,:version_txt,:version_no,:id_prev_version,:name,:code,:description,:remark,:file_name,:ext,:mime_type,:save_mode,:file_path,:status,:creator)";
		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		FileModel obj = (FileModel) model;

		// set parameters here
		if (obj.getIdDocument() != Integer.MIN_VALUE) {
			st.setObject("id_document", obj.getIdDocument());
		} else {
			st.setObject("id_document", null);
		}
		if (obj.getObjectType() != null) {
			st.setObject("object_type", obj.getObjectType());
		} else {
			st.setObject("object_type", null);
		}
		if (obj.getObjectId() != Integer.MIN_VALUE) {
			st.setObject("object_id", obj.getObjectId());
		} else {
			st.setObject("object_id", null);
		}
		if (obj.getVersionTxt() != null) {
			st.setObject("version_txt", obj.getVersionTxt());
		} else {
			st.setObject("version_txt", null);
		}
		if (obj.getVersionNo() != Integer.MIN_VALUE) {
			st.setObject("version_no", obj.getVersionNo());
		} else {
			st.setObject("version_no", null);
		}
		if (obj.getIdPrevVersion() != Integer.MIN_VALUE) {
			st.setObject("id_prev_version", obj.getIdPrevVersion());
		} else {
			st.setObject("id_prev_version", null);
		}
		if (obj.getName() != null) {
			st.setObject("name", obj.getName());
		} else {
			st.setObject("name", null);
		}
		if (obj.getCode() != null) {
			st.setObject("code", obj.getCode());
		} else {
			st.setObject("code", null);
		}
		if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
			st.setObject("description", null);
		}
		if (obj.getRemark() != null) {
			st.setObject("remark", obj.getRemark());
		} else {
			st.setObject("remark", null);
		}
		if (obj.getFileName() != null) {
			st.setObject("file_name", obj.getFileName());
		} else {
			st.setObject("file_name", null);
		}
		if (obj.getExt() != null) {
			st.setObject("ext", obj.getExt());
		} else {
			st.setObject("ext", null);
		}
		if (obj.getMimeType() != null) {
			st.setObject("mime_type", obj.getMimeType());
		} else {
			st.setObject("mime_type", null);
		}
		if (obj.getSaveMode() != Integer.MIN_VALUE) {
			st.setObject("save_mode", obj.getSaveMode());
		} else {
			st.setObject("save_mode", null);
		}
		if (obj.getFilePath() != null) {
			st.setObject("file_path", obj.getFilePath());
		} else {
			st.setObject("file_path", null);
		}
		if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
			st.setObject("status", null);
		}
		if (obj.getCreator() != Integer.MIN_VALUE) {
			st.setObject("creator", obj.getCreator());
		} else {
			st.setObject("creator", null);
		}

		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genUpdateStatement(Connection dbConn, IModel model)
			throws SQLException {
		String sql = "SELECT sp_file_update(:id,:id_document,:object_type,:object_id,:version_txt,:version_no,:id_prev_version,:name,:code,:description,:remark,:file_name,:ext,:mime_type,:save_mode,:file_path,:status,:updator,:deleted,:deletion_time)";

		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		FileModel obj = (FileModel) model;

		// set parameters here
		if (obj.getId() != Integer.MIN_VALUE) {
			st.setObject("id", obj.getId());
		} else {
			st.setObject("id", null);
		}
		if (obj.getIdDocument() != Integer.MIN_VALUE) {
			st.setObject("id_document", obj.getIdDocument());
		} else {
			st.setObject("id_document", null);
		}
		if (obj.getObjectType() != null) {
			st.setObject("object_type", obj.getObjectType());
		} else {
			st.setObject("object_type", null);
		}
		if (obj.getObjectId() != Integer.MIN_VALUE) {
			st.setObject("object_id", obj.getObjectId());
		} else {
			st.setObject("object_id", null);
		}
		if (obj.getVersionTxt() != null) {
			st.setObject("version_txt", obj.getVersionTxt());
		} else {
			st.setObject("version_txt", null);
		}
		if (obj.getVersionNo() != Integer.MIN_VALUE) {
			st.setObject("version_no", obj.getVersionNo());
		} else {
			st.setObject("version_no", null);
		}
		if (obj.getIdPrevVersion() != Integer.MIN_VALUE) {
			st.setObject("id_prev_version", obj.getIdPrevVersion());
		} else {
			st.setObject("id_prev_version", null);
		}
		if (obj.getName() != null) {
			st.setObject("name", obj.getName());
		} else {
			st.setObject("name", null);
		}
		if (obj.getCode() != null) {
			st.setObject("code", obj.getCode());
		} else {
			st.setObject("code", null);
		}
		if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
			st.setObject("description", null);
		}
		if (obj.getRemark() != null) {
			st.setObject("remark", obj.getRemark());
		} else {
			st.setObject("remark", null);
		}
		if (obj.getFileName() != null) {
			st.setObject("file_name", obj.getFileName());
		} else {
			st.setObject("file_name", null);
		}
		if (obj.getExt() != null) {
			st.setObject("ext", obj.getExt());
		} else {
			st.setObject("ext", null);
		}
		if (obj.getMimeType() != null) {
			st.setObject("mime_type", obj.getMimeType());
		} else {
			st.setObject("mime_type", null);
		}
		if (obj.getSaveMode() != Integer.MIN_VALUE) {
			st.setObject("save_mode", obj.getSaveMode());
		} else {
			st.setObject("save_mode", null);
		}
		if (obj.getFilePath() != null) {
			st.setObject("file_path", obj.getFilePath());
		} else {
			st.setObject("file_path", null);
		}
		if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
			st.setObject("status", null);
		}
		if (obj.getUpdator() != Integer.MIN_VALUE) {
			st.setObject("updator", obj.getUpdator());
		} else {
			st.setObject("updator", null);
		}
		if (obj.getDeletedSet()) {
			st.setObject("deleted", obj.getDeleted());
		} else {
			st.setObject("deleted", null);
		}
		if (obj.getDeletionTime() != null) {
			st.setObject("deletion_time", obj.getDeletionTime());
		} else {
			st.setObject("deletion_time", null);
		}

		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genDeleteStatement(Connection dbConn, IModel query)
			throws SQLException {
		String sql = "select sp_file_delete(:id);";
		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		FileModel obj = (FileModel) query;

		// set primary keys
		st.setObject("id", obj.getId());

		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genCountStatement(Connection dbConn,
			IModelExt input) throws SQLException {
		String sql = "SELECT sp_file_count(:id,:id_document,:object_type,:object_id,:version_txt,:version_no,:id_prev_version,:name,:code,:description,:remark,:file_name,:ext,:mime_type,:save_mode,:file_path,:status,:createdFrom,:createdTo,:creator,:updatedFrom,:updatedTo,:updator,:deleted,:deletion_timeFrom,:deletion_timeTo)";

		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		FileModelExt obj = (FileModelExt) input;

		// set parameters here
		if (obj.getId() != Integer.MIN_VALUE) {
			st.setObject("id", obj.getId());
		} else {
			st.setObject("id", null);
		}
		if (obj.getIdDocument() != Integer.MIN_VALUE) {
			st.setObject("id_document", obj.getIdDocument());
		} else {
			st.setObject("id_document", null);
		}
		if (obj.getObjectType() != null) {
			st.setObject("object_type", obj.getObjectType());
		} else {
			st.setObject("object_type", null);
		}
		if (obj.getObjectId() != Integer.MIN_VALUE) {
			st.setObject("object_id", obj.getObjectId());
		} else {
			st.setObject("object_id", null);
		}
		if (obj.getVersionTxt() != null) {
			st.setObject("version_txt", obj.getVersionTxt());
		} else {
			st.setObject("version_txt", null);
		}
		if (obj.getVersionNo() != Integer.MIN_VALUE) {
			st.setObject("version_no", obj.getVersionNo());
		} else {
			st.setObject("version_no", null);
		}
		if (obj.getIdPrevVersion() != Integer.MIN_VALUE) {
			st.setObject("id_prev_version", obj.getIdPrevVersion());
		} else {
			st.setObject("id_prev_version", null);
		}
		if (obj.getName() != null) {
			st.setObject("name", obj.getName());
		} else {
			st.setObject("name", null);
		}
		if (obj.getCode() != null) {
			st.setObject("code", obj.getCode());
		} else {
			st.setObject("code", null);
		}
		if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
			st.setObject("description", null);
		}
		if (obj.getRemark() != null) {
			st.setObject("remark", obj.getRemark());
		} else {
			st.setObject("remark", null);
		}
		if (obj.getFileName() != null) {
			st.setObject("file_name", obj.getFileName());
		} else {
			st.setObject("file_name", null);
		}
		if (obj.getExt() != null) {
			st.setObject("ext", obj.getExt());
		} else {
			st.setObject("ext", null);
		}
		if (obj.getMimeType() != null) {
			st.setObject("mime_type", obj.getMimeType());
		} else {
			st.setObject("mime_type", null);
		}
		if (obj.getSaveMode() != Integer.MIN_VALUE) {
			st.setObject("save_mode", obj.getSaveMode());
		} else {
			st.setObject("save_mode", null);
		}
		if (obj.getFilePath() != null) {
			st.setObject("file_path", obj.getFilePath());
		} else {
			st.setObject("file_path", null);
		}
		if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
			st.setObject("status", null);
		}
		if (obj.getCreatedFrom() != null) {
			st.setObject("createdFrom", obj.getCreatedFrom());
		} else {
			st.setObject("createdFrom", null);
		}
		if (obj.getCreatedTo() != null) {
			st.setObject("createdTo", obj.getCreatedTo());
		} else {
			st.setObject("createdTo", null);
		}
		if (obj.getCreator() != Integer.MIN_VALUE) {
			st.setObject("creator", obj.getCreator());
		} else {
			st.setObject("creator", null);
		}
		if (obj.getUpdatedFrom() != null) {
			st.setObject("updatedFrom", obj.getUpdatedFrom());
		} else {
			st.setObject("updatedFrom", null);
		}
		if (obj.getUpdatedTo() != null) {
			st.setObject("updatedTo", obj.getUpdatedTo());
		} else {
			st.setObject("updatedTo", null);
		}
		if (obj.getUpdator() != Integer.MIN_VALUE) {
			st.setObject("updator", obj.getUpdator());
		} else {
			st.setObject("updator", null);
		}
		if (obj.getDeletedSet()) {
			st.setObject("deleted", obj.getDeleted());
		} else {
			st.setObject("deleted", null);
		}
		if (obj.getDeletionTimeFrom() != null) {
			st.setObject("deletion_timeFrom", obj.getDeletionTimeFrom());
		} else {
			st.setObject("deletion_timeFrom", null);
		}
		if (obj.getDeletionTimeTo() != null) {
			st.setObject("deletion_timeTo", obj.getDeletionTimeTo());
		} else {
			st.setObject("deletion_timeTo", null);
		}

		return st.getPreparedStatement();
	}

	public FileModel clone() {
		FileModel obj = new FileModel();

		obj.setId(getId());
		obj.setIdDocument(getIdDocument());
		obj.setObjectType(getObjectType());
		obj.setObjectId(getObjectId());
		obj.setVersionTxt(getVersionTxt());
		obj.setVersionNo(getVersionNo());
		obj.setIdPrevVersion(getIdPrevVersion());
		obj.setName(getName());
		obj.setCode(getCode());
		obj.setDescription(getDescription());
		obj.setRemark(getRemark());
		obj.setFileName(getFileName());
		obj.setExt(getExt());
		obj.setMimeType(getMimeType());
		obj.setSaveMode(getSaveMode());
		obj.setFilePath(getFilePath());
		obj.setStatus(getStatus());
		obj.setCreated(getCreated());
		obj.setCreator(getCreator());
		obj.setUpdated(getUpdated());
		obj.setUpdator(getUpdator());
		obj.setDeleted(getDeleted());
		obj.setDeletionTime(getDeletionTime());

		return obj;
	}

}